package com.sttk.secreconeclick.bookkeep.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.basic.ProviderMultiAdapter;
import com.sttk.secreconeclick.bookkeep.R;
import com.sttk.secreconeclick.bookkeep.bean.BillTypeBean;

public class BillTypeAdapter extends ProviderMultiAdapter<BillTypeBean> {

    private int selPosition;

    public BillTypeAdapter() {
        addItemProvider(new BillTypeProvider());
    }

    public void setSelPosition(int selPosition) {
        this.selPosition = selPosition;
        notifyDataSetChanged();
    }

    private class BillTypeProvider extends BaseItemProvider<BillTypeBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_bill_type;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, BillTypeBean bean) {
            baseViewHolder.setText(R.id.tvBillTypeItemName, bean.getName());
            if (baseViewHolder.getBindingAdapterPosition() == selPosition) {
                baseViewHolder.setImageResource(R.id.ivBillTypeItemImg, bean.getSelIcon());
            } else {
                baseViewHolder.setImageResource(R.id.ivBillTypeItemImg, bean.getIcon());
            }
        }
    }
}